
var CHAR_TILDE = 126;
var CODE_FNC1 = 102;
var SET_STARTA = 103;
var SET_STARTB = 104;
var SET_STARTC = 105;
var SET_SHIFT = 98;
var SET_CODEA = 101;
var SET_CODEB = 100;
var SET_STOP = 106;
var REPLACE_CODES = {
  "CHAR_TILDE": 102
};
var CODESET = {
  "ANY": 1,
  "AB": 2,
  "A": 3,
  "B": 4,
  "C": 5
};

function getBytes(_0x39fb02) {
  var _0x17cde8 = [];

  for (var _0x465bd0 = 0; _0x465bd0 < _0x39fb02.length; _0x465bd0++) {
    _0x17cde8.push(_0x39fb02.charCodeAt(_0x465bd0));
  }

  return _0x17cde8;
}

exports.code128 = function (_0x59c8ca, _0x240e08, _0x1094c6, _0x349e37, _0x1aef5e, _0x138746) {
  _0x1094c6 = parseInt(_0x1094c6);
  _0x349e37 = parseInt(_0x349e37);
  _0x1aef5e = parseInt(_0x1aef5e);
  _0x138746 = parseInt(_0x138746);

  var _0x437758 = stringToCode128(_0x240e08);

  var _0xd517ac = new Graphics(_0x59c8ca, _0x1aef5e, _0x138746);

  var _0x14d3b2 = _0xd517ac.area.width / ((_0x437758.length - 3) * 11 + 35);

  var _0x18d25f = _0xd517ac.area.left;

  var _0x921b3e = _0xd517ac.area.top;

  for (var i = 0; i < _0x437758.length; i++) {
    var _0x27f9c3 = _0x437758[i];

    for (var i = 0; i < 8; i += 2) {
      var _0x5c6f69 = PATTERNS[_0x27f9c3][i] * _0x14d3b2;

      var _0x54e11d = _0x138746 - _0x921b3e;

      var _0x777105 = PATTERNS[_0x27f9c3][i + 1] * _0x14d3b2;

      if (_0x5c6f69 > 0) {
        _0xd517ac.fillFgRect(_0x1094c6 + _0x18d25f, _0x349e37 + _0x921b3e, _0x5c6f69, _0x54e11d);
      }

      _0x18d25f += _0x5c6f69 + _0x777105;
    }
  }
};

function stringToCode128(_0xd1b0e3) {
  var _0x560a1c = {
    "currcs": 5
  };

  var _0x422205 = getBytes(_0xd1b0e3);

  var _0x7a5fd = _0x422205[0] == 126 ? 1 : 0;

  var _0x391742 = _0x422205.length > 0 ? codeSetAllowedFor(_0x422205[_0x7a5fd++]) : 2;

  var _0x11018a = _0x422205.length > 0 ? codeSetAllowedFor(_0x422205[_0x7a5fd++]) : 2;

  _0x560a1c.currcs = _0x28414f(_0x391742, _0x11018a);
  _0x560a1c.currcs = _0x5e9d3d(_0x422205, _0x560a1c.currcs);

  var _0x446560 = new Array();

  switch (_0x560a1c.currcs) {
    case CODESET.A:
      _0x446560.push(103);

      break;

    case CODESET.B:
      _0x446560.push(104);

      break;

    default:
      _0x446560.push(105);

      break;
  }

  for (var i = 0; i < _0x422205.length; i++) {
    var _0x535cea = _0x422205[i];

    if (_0x535cea in REPLACE_CODES) {
      _0x446560.push(REPLACE_CODES[_0x535cea]);

      i++;
      _0x535cea = _0x422205[i];
    }

    var _0x21611d = _0x422205.length > i + 1 ? _0x422205[i + 1] : -1;

    _0x446560 = _0x446560.concat(_0x479182(_0x535cea, _0x21611d, _0x560a1c.currcs));
    if (_0x560a1c.currcs == 5) i++;
  }

  var _0x34e09f = _0x446560[0];

  for (var i = 1; i < _0x446560.length; i++) {
    _0x34e09f += i * _0x446560[i];
  }

  _0x446560.push(_0x34e09f % 103);

  _0x446560.push(106);

  return _0x446560;

  function _0x28414f(_0x4ec32b, _0x4c25dd) {
    var _0x1fd330 = 0;
    _0x1fd330 += _0x4ec32b == CODESET.A ? 1 : 0;
    _0x1fd330 += _0x4ec32b == CODESET.B ? -1 : 0;
    _0x1fd330 += _0x4c25dd == CODESET.A ? 1 : 0;
    _0x1fd330 += _0x4c25dd == CODESET.B ? -1 : 0;
    return _0x1fd330 > 0 ? CODESET.A : CODESET.B;
  }

  function _0x5e9d3d(_0x3bb55b, _0x50adf7) {
    for (var i = 0; i < _0x3bb55b.length; i++) {
      var _0x2772b9 = _0x3bb55b[i];
      if ((_0x2772b9 < 48 || _0x2772b9 > 57) && _0x2772b9 != 126) return _0x50adf7;
    }

    return 5;
  }

  function _0x479182(_0x1a0ff6, _0x465175, _0x20d6d2) {
    var _0x59cdbc = [];

    var _0xdd2cd7 = -1;

    if (charCompatible(_0x1a0ff6, _0x20d6d2)) {
      if (_0x20d6d2 == 5) {
        if (_0x465175 == -1) {
          _0xdd2cd7 = 100;
          _0x20d6d2 = CODESET.B;
        } else if (_0x465175 != -1 && !charCompatible(_0x465175, _0x20d6d2)) {
          if (charCompatible(_0x465175, CODESET.A)) {
            _0xdd2cd7 = 101;
            _0x20d6d2 = CODESET.A;
          } else {
            _0xdd2cd7 = 100;
            _0x20d6d2 = CODESET.B;
          }
        }
      }
    } else {
      if (_0x465175 != -1 && !charCompatible(_0x465175, _0x20d6d2)) {
        switch (_0x20d6d2) {
          case CODESET.A:
            _0xdd2cd7 = 100;
            _0x20d6d2 = CODESET.B;
            break;

          case CODESET.B:
            _0xdd2cd7 = 101;
            _0x20d6d2 = CODESET.A;
            break;
        }
      } else {
        _0xdd2cd7 = 98;
      }
    }

    if (_0xdd2cd7 != -1) {
      _0x59cdbc.push(_0xdd2cd7);

      _0x59cdbc.push(codeValue(_0x465175));
    } else {
      if (_0x20d6d2 == 5) {
        _0x59cdbc.push(codeValue(_0x1a0ff6, _0x465175));
      } else {
        _0x59cdbc.push(codeValue(_0x1a0ff6));
      }
    }

    _0x560a1c.currcs = _0x20d6d2;
    return _0x59cdbc;
  }
}

function codeValue(_0xee68d8, _0xb8e8e5) {
  if (typeof _0xb8e8e5 == "undefined") {
    return _0xee68d8 >= 32 ? _0xee68d8 - 32 : _0xee68d8 + 64;
  } else {
    return parseInt(String.fromCharCode(_0xee68d8) + String.fromCharCode(_0xb8e8e5));
  }
}

function charCompatible(_0x3f3d53, _0x81a141) {
  var _0x388eb2 = codeSetAllowedFor(_0x3f3d53);

  if (_0x388eb2 == CODESET.ANY) return true;
  if (_0x388eb2 == 2) return true;
  if (_0x388eb2 == CODESET.A && _0x81a141 == CODESET.A) return true;
  if (_0x388eb2 == CODESET.B && _0x81a141 == CODESET.B) return true;
  return false;
}

function codeSetAllowedFor(_0x5bf6b5) {
  if (_0x5bf6b5 >= 48 && _0x5bf6b5 <= 57) {
    return 1;
  } else if (_0x5bf6b5 >= 32 && _0x5bf6b5 <= 95) {
    return 2;
  } else {
    return _0x5bf6b5 < 32 ? CODESET.A : CODESET.B;
  }
}

var Graphics = function (ctx, width, height) {
  this.width = width;
  this.height = height;
  this.quiet = Math.round(this.width / 40);
  this.border_size = 0;
  this.padding_width = 0;
  this.area = {
    "width": width - this.padding_width * 2 - this.quiet * 2,
    "height": height - this.border_size * 2,
    "top": this.border_size - 4,
    "left": this.padding_width + this.quiet
  };
  this.ctx = ctx;
  this.fg = '#000000';
  this.bg = "#ffffff";
};

Graphics.prototype.__fillRect = function (_0x317563, _0x13e47b, _0x22cbc9, _0x2e86a6, _0x2ac1da) {
  this.ctx.setFillStyle(_0x2ac1da);

  this.ctx.fillRect(_0x317563, _0x13e47b, _0x22cbc9, _0x2e86a6);
};

Graphics.prototype.fillFgRect = function (_0x3b22c4, _0x596c09, _0x44e9f1, _0x37cf58) {
  this.__fillRect(_0x3b22c4, _0x596c09, _0x44e9f1, _0x37cf58, this.fg);
};

Graphics.prototype.fillBgRect = function (_0xba6c1, _0x5e6ff6, _0x37e0d3, _0x430531) {
  this._fillRect(_0xba6c1, _0x5e6ff6, _0x37e0d3, _0x430531, this.bg);
};

var PATTERNS = [[2, 1, 2, 2, 2, 2, 0, 0], [2, 2, 2, 1, 2, 2, 0, 0], [2, 2, 2, 2, 2, 1, 0, 0], [1, 2, 1, 2, 2, 3, 0, 0], [1, 2, 1, 3, 2, 2, 0, 0], [1, 3, 1, 2, 2, 2, 0, 0], [1, 2, 2, 2, 1, 3, 0, 0], [1, 2, 2, 3, 1, 2, 0, 0], [1, 3, 2, 2, 1, 2, 0, 0], [2, 2, 1, 2, 1, 3, 0, 0], [2, 2, 1, 3, 1, 2, 0, 0], [2, 3, 1, 2, 1, 2, 0, 0], [1, 1, 2, 2, 3, 2, 0, 0], [1, 2, 2, 1, 3, 2, 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